from math import sqrt
from numpy import array

def cosine_distance(a, b):
    a = array(a)
    b = array(b)
    numerator=(a*b).sum()
    denoma=(a*a).sum()
    denomb=(b*b).sum()
    result = numerator / sqrt(denoma*denomb)
    return result
    
#     result = 1
#     for elem in b:
#         result *= elem
#     return result

# print cosine_distance([1,1,1], [4,4,1])
# print cosine_distance([2,1], [4,1])